<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息 - 在线影院订票系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .profile-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem 0;
        }
        .profile-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            margin-bottom: 2rem;
        }
        .profile-avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            border: 4px solid white;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        .form-label {
            font-weight: 600;
            color: #495057;
        }
        .readonly-field {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
        }
        .info-item {
            padding: 0.75rem 0;
            border-bottom: 1px solid #f1f3f4;
        }
        .info-label {
            font-weight: 600;
            color: #666;
            width: 100px;
            display: inline-block;
        }
        .info-value {
            color: #333;
        }
    </style>
</head>
<body class="bg-light">
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
        <div class="container">
            <a class="navbar-brand fw-bold text-primary" href="${pageContext.request.contextPath}/movies">
                <i class="fas fa-film me-2"></i>在线影院
            </a>

            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="${pageContext.request.contextPath}/movies">
                    <i class="fas fa-film me-1"></i>电影
                </a>
                <div class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-user me-1"></i>${sessionScope.user.username}
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/user/orders">
                            <i class="fas fa-ticket-alt me-2"></i>我的订单
                        </a></li>
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/user/profile">
                            <i class="fas fa-user-edit me-2"></i>个人信息
                        </a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/logout">
                            <i class="fas fa-sign-out-alt me-2"></i>退出登录
                        </a></li>
                    </ul>
                </div>
            </div>
        </div>
    </nav>

    <!-- 个人信息头部 -->
    <section class="profile-header">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-3 text-center">
                    <img src="${user.avatar != null ? user.avatar : '/images/default-avatar.jpg'}"
                         class="profile-avatar" alt="用户头像">
                </div>
                <div class="col-md-9">
                    <h2>个人信息</h2>
                    <p class="mb-0">管理您的账户信息和偏好设置</p>
                </div>
            </div>
        </div>
    </section>

    <div class="container mt-4">
        <!-- 成功消息 -->
        <c:if test="${not empty message}">
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fas fa-check-circle me-2"></i>${message}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </c:if>

        <!-- 错误信息 -->
        <c:if test="${not empty error}">
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fas fa-exclamation-triangle me-2"></i>${error}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </c:if>

        <!-- 返回按钮 -->
        <div class="mb-3">
            <a href="${pageContext.request.contextPath}/movies" class="btn btn-outline-primary">
                <i class="fas fa-arrow-left me-1"></i>返回首页
            </a>
        </div>

        <div class="row">
            <!-- 基本信息展示 -->
            <div class="col-md-6">
                <div class="card profile-card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>基本信息</h5>
                    </div>
                    <div class="card-body">
                        <div class="info-item">
                            <span class="info-label">用户名：</span>
                            <span class="info-value">${user.username}</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">手机号：</span>
                            <span class="info-value">${user.phone}</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">邮箱：</span>
                            <span class="info-value">${not empty user.email ? user.email : '未设置'}</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">真实姓名：</span>
                            <span class="info-value">${not empty user.realName ? user.realName : '未设置'}</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">性别：</span>
                            <span class="info-value">
                                <c:choose>
                                    <c:when test="${user.gender == 'M' || user.gender == 'MALE'}">男</c:when>
                                    <c:when test="${user.gender == 'F' || user.gender == 'FEMALE'}">女</c:when>
                                    <c:otherwise>未设置</c:otherwise>
                                </c:choose>
                            </span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">生日：</span>
                            <span class="info-value">
                                <c:choose>
                                    <c:when test="${not empty user.birthDate}">
                                        <fmt:formatDate value="${user.birthDate}" pattern="yyyy年MM月dd日"/>
                                    </c:when>
                                    <c:otherwise>未设置</c:otherwise>
                                </c:choose>
                            </span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">注册时间：</span>
                            <span class="info-value">
                                <c:choose>
                                    <c:when test="${not empty user.createdAt}">
                                        <fmt:formatDate value="${user.createdAt}" pattern="yyyy年MM月dd日"/>
                                    </c:when>
                                    <c:otherwise>--</c:otherwise>
                                </c:choose>
                            </span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 编辑信息表单 -->
            <div class="col-md-6">
                <div class="card profile-card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-edit me-2"></i>编辑信息</h5>
                    </div>
                    <div class="card-body">
                        <form method="post" action="${pageContext.request.contextPath}/user/profile">
                            <input type="hidden" name="action" value="update">

                            <!-- 用户名（只读） -->
                            <div class="mb-3">
                                <label class="form-label">用户名</label>
                                <input type="text" class="form-control readonly-field"
                                       value="${user.username}" readonly>
                                <small class="text-muted">用户名不可修改</small>
                            </div>

                            <!-- 手机号（只读） -->
                            <div class="mb-3">
                                <label class="form-label">手机号</label>
                                <input type="text" class="form-control readonly-field"
                                       value="${user.phone}" readonly>
                                <small class="text-muted">手机号不可修改</small>
                            </div>

                            <!-- 邮箱 -->
                            <div class="mb-3">
                                <label for="email" class="form-label">邮箱</label>
                                <input type="email" class="form-control" id="email" name="email"
                                       value="${user.email}" placeholder="请输入邮箱地址">
                            </div>

                            <!-- 真实姓名 -->
                            <div class="mb-3">
                                <label for="realName" class="form-label">真实姓名</label>
                                <input type="text" class="form-control" id="realName" name="realName"
                                       value="${user.realName}" placeholder="请输入真实姓名">
                            </div>

                            <!-- 性别 -->
                            <div class="mb-3">
                                <label class="form-label">性别</label>
                                <div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="radio" name="gender"
                                               id="male" value="M" ${user.gender == 'M' || user.gender == 'MALE' ? 'checked' : ''}>
                                        <label class="form-check-label" for="male">男</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="radio" name="gender"
                                               id="female" value="F" ${user.gender == 'F' || user.gender == 'FEMALE' ? 'checked' : ''}>
                                        <label class="form-check-label" for="female">女</label>
                                    </div>
                                </div>
                            </div>

                            <!-- 生日 -->
                            <div class="mb-3">
                                <label for="birthDate" class="form-label">生日</label>
                                <input type="date" class="form-control" id="birthDate" name="birthDate"
                                       value="<fmt:formatDate value='${user.birthDate}' pattern='yyyy-MM-dd'/>">
                            </div>

                            <!-- 提交按钮 -->
                            <div class="d-grid">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-save me-2"></i>保存修改
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
